package com.slf.flow.oss.function.extension;

import com.slf.flow.oss.model.Oss;
import com.slf.flow.oss.service.OssService;
import com.slf.flow.oss.utils.MinioOSSUtil;
import com.slf.flow.oss.utils.OSSUtil;
import com.slf.flow.executor.FunctionExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class OssBytesFunctionExtension implements FunctionExtension{
	
	private static OssService ossService;
	
	@Autowired
	private void setOssMapper(OssService ossService) {
		OssBytesFunctionExtension.ossService = ossService;
	}

	@Override
	public Class<?> support() {
		return Object[].class;
	}
	
//	public static OssFile ossUpload(Object[] objects,String ossId,String filePath) throws Exception {
//		byte[] bytes = new byte[objects.length];
//		for (int i = 0; i < objects.length; i++) {
//			bytes[i] = (byte)objects[i];
//		}
//		Oss oss = ossService.getOss(ossId);
//		if(null != oss) {
//			return OSSUtil.uploadFileToOss(oss, bytes, filePath);
//		}
//		if(null == oss) {
//		} else if("aliyun".equals(oss.getType())){
//			return OSSUtil.uploadFileToOss(oss, bytes, filePath);
//		} else if("minio".equals(oss.getType())){
//			return MinioOSSUtil.uploadFileToOss(oss, bytes, filePath);
//		}
//		return null;
//	}
	public static Map<String, Object> ossUpload(String url, String ossId, String filePath) throws Exception {
		Oss oss = ossService.getOss(ossId);
		if(null == oss) {
		} else if("aliyun".equals(oss.getType())){
			return OSSUtil.uploadFileToOss(oss,url,filePath);
		} else if("minio".equals(oss.getType())){
			return MinioOSSUtil.uploadFileToOss(oss,url,filePath);
		}
		return null;
	}

}